﻿/******************************************************************
** 文 件 名: BD_ProjectBudget_DAL.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-3-11 18:27:33
** 描    述: 实现公共部分的数据访问封装，提供项目概算的数据访问类
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.DataAccess
{
	/// <summary>
    /// BD_ProjectBudget数据访问类
    /// </summary>
	public partial class BD_ProjectBudget_DAL : BaseDataAccess<BD_ProjectBudget>
    {		
		/// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
        public BD_ProjectBudget_DAL(string connectionStringName)
            : base(connectionStringName)
        {

        }

        public DataTable GetProjectBudget(string projectId, string projectName,string projectCategory, int pageSize, int currentPageIndex, out int pageCount, out int recordCount)
        {
            DbParameter pProjectID = CreateParameter("ProjectID");
            pProjectID.DbType = DbType.String;
            pProjectID.Value=projectId;
            DbParameter pProjectName = CreateParameter("Name");
            pProjectName.DbType = DbType.String;
            pProjectName.Value=projectName;
            DbParameter pProjectCategory = CreateParameter("ProjectCategory");
            pProjectCategory.DbType = DbType.String;
            pProjectCategory.Value = projectCategory;
            string sql = string.Format(@"Select A.*,B.Name ProjectName,B.SortCode
                From BD_ProjectBudget A Inner Join
                BD_Project B On A.ProjectID=B.ID
                Where 1=1 {0} {1} {2}",
                                  string.IsNullOrEmpty(projectId) ? "" : string.Format(" And A.ProjectID={0}", pProjectID.ParameterName),
                                  string.IsNullOrEmpty(projectName) ? "" : string.Format(" And B.Name Like '%'+{0}+'%'", pProjectName.ParameterName),
                                  string.IsNullOrEmpty(projectCategory) ? "" : string.Format(" And B.ProjectCategory={0}", pProjectCategory.ParameterName));
            DbCommand command = GetDbCommand(sql);
            if (!string.IsNullOrEmpty(projectId)) { command.Parameters.Add(pProjectID); }
            if (!string.IsNullOrEmpty(projectName)) { command.Parameters.Add(pProjectName); }
            if (!string.IsNullOrEmpty(projectCategory)) { command.Parameters.Add(pProjectCategory); }
            return ExecuteDataTable(command, "SortCode,changeDate Desc,CreateTime Desc", pageSize, currentPageIndex, out pageCount, out recordCount);
        }
    }
}
